package edu.hawaii.halealohacli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;

/**
 * A JUnit test for testing MonitorGoal for correctness. Very few tests as power data and baseline
 * data come from their respective methods.
 * 
 * @author John MacMillan
 */

public class TestMonitorGoal {

  MonitorGoal testMB;
  String error;
  String[] args;
  String url = "http://server.wattdepot.org:8190/wattdepot/";

  /**
   * Create a MonitorGoal object to test.
   */
  public TestMonitorGoal() {
    testMB = new MonitorGoal();
  }

  /**
   * Test initializeCommand method for correct argument handling.
   * Also tests for correct filtering of valid goal %.
   */
  @Test
  public void testInitializeCommand() {
    // URL is blank to avoid accessing server unnecessarily
    String url2 = "http://";
    args = new String[4];
    args[2] = String.valueOf(50);
    args[3] = String.valueOf(5);
    args[2] = String.valueOf(100);
    error = "testInitializeCommand (4) failed: Expected false";
    assertFalse(error, testMB.initializeCommand(new WattDepotClient(url2), args));
    args[2] = String.valueOf(0);
    error = "testInitializeCommand (5) failed: Expected false";
    assertFalse(error, testMB.initializeCommand(new WattDepotClient(url2), args));
    // Initialization should fail without enough arguments
    args = new String[1];
    error = "testInitializeCommand (6) failed: Expected false";
    assertFalse(error, testMB.initializeCommand(new WattDepotClient(url2), args));
    // Initialization should fail with too many arguments
    args = new String[5];
    error = "testInitializeCommand (7) failed: Expected false";
    assertFalse(error, testMB.initializeCommand(new WattDepotClient(url2), args));
  }

  /**
   * Test getName method for correct output.
   */
  @Test
  public void testGetName() {
    System.out.println("Testing getName...");
    args = new String[4];
    testMB.initializeCommand(new WattDepotClient(url), args);
    error = "testGetName failed: Message does not match expected values";
    assertTrue(error, testMB.getName().equals("monitor-goal"));
  }
}
